// --------------------------------------------------------------------
//   name 	: 	Add Comma Plugin
//   desc 	: 	Adds a comma in the resources display areas.
//   version	: 	0.9e
//   dev 	: 	JelianSD
// --------------------------------------------------------------------
// DEPENDENCIES
// 
// --------------------------------------------------------------------
// CHANGE HISTORY
// 0.1 	Initial Release
// 0.9e	Various updates
// 0.9i	Major update, uses jquery now
// --------------------------------------------------------------------
	plugins.addComma = {
		'comma_return':function (input,Seperator) {
			if(new String(Seperator)=='undefined') Seperator=",";
			var current = parseInt(input);
			var commaOutput="";
			for(var i=0;i<(current+"").length;i++) {
				commaOutput = commaOutput + "" + (current+"").charAt(i);
				if(((current+"").length-i-1)%3==0) commaOutput = commaOutput + Seperator;
			}
			commaOutput = commaOutput.substr(0,commaOutput.length-1);
			return commaOutput;
		},
		'enhance_game' : function() {
			var Seperator = getValuePlugin("ComaPluginSeperator");
			$('#wood').hide();
			$('#wood').parent().append("<b style='text-decoration:none;font-weight:normal;' id='woodcoma' title='"+ $('#wood').attr('title') +"'>"+ $('#wood').html()+"</b>");
			$('#stone').hide();
			$('#stone').parent().append("<b style='text-decoration:none;font-weight:normal;' id='stonecoma' title='"+$('#stone').attr('title')+"'>"+$('#stone').html()+"</b>");
			$('#iron').hide();
			$('#iron').parent().append("<b style='text-decoration:none;font-weight:normal;' id='ironcoma' title='"+ $('#iron').attr('title') +"'>"+ $('#iron').html()+"</b>");
			
			var original_tickRes = unsafeWindow.tickRes;
			setFunc('tickRes', function(res) {
				original_tickRes(res);
				$('#'+res["name"]+'coma').html(plugins.addComma.comma_return( eval($('#'+res["name"]).text()),Seperator ));
				$('#'+res["name"]+'coma').addClass( $('#'+res["name"]).attr('class') );
			});
			
			$('#storage').hide();
			$('#storage').parent().append("<td id='storagecoma'>"+plugins.addComma.comma_return(eval( $('#storage').text() ),Seperator)+"</td>");
			
			var FarmTDV1 = $('table[class="box"] td[align="center"]:contains("/"):first').text();
			if(FarmTDV1) {
				var FarmLevels = FarmTDV1.split("/");
				$('table[class="box"] td[align="center"]:contains("/"):first').hide();
				$('table[class="box"] td[align="center"]:contains("/"):first').parent().append("<td align='center'>"+plugins.addComma.comma_return( parseInt(FarmLevels[0]), Seperator )+"/"+plugins.addComma.comma_return( parseInt(FarmLevels[1]) )+"</td>");
			}
		},
		'info' : {
			'mandatory' : false,
			'name' : "Change resource display",
			'desc' : "Adds commas into the resources fields to show thousands and millions etc",
			'version' : "Beta v0.9i",
			'dev' : "JelianSD"
		},
		'variables' : {
			'tooltip':["The seperator to seperate thousands by"],
			'ComaPluginSeperator':","
		}
	}